import numpy as np
import matplotlib.pyplot as plt

# 阶跃函数
def step_function(x):
    # x>0 True or False
    # Python中将布尔型转换为int型后，True会转换为1，False会转换为0。
    return np.array(x > 0, dtype=int)

def sigmoid(x):
    return 1/(1+np.exp(-x))

def relu(x):
    return np.maximum(0, x)


if __name__ == '__main__':
    x = np.arange(-5.0, 5.0, 0.1)
    y = step_function(x)
    y1  = sigmoid(x)
    y3 = relu(x)
    fig,ax = plt.subplots()
    ax.plot(x, y,color='r',label='step',linestyle='--')
    ax.plot(x, y1,color='b',label='sigmoid')
    ax.plot(x, y3,color='g',label='relu')
    plt.ylim(-0.1, 1.1)
    # 显示图例
    plt.legend()
    plt.show()
